//
//  ViewController.m
//  MyProject
//
//  Created by yun on 2018/3/21.
//  Copyright © 2018年 yun. All rights reserved.
//

#import "ViewController.h"
#import <objc/runtime.h>
#import "TestObject.h"
#import <objc/message.h>
@interface ViewController ()


@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
}

- (void)deviceInfo{
    unsigned int count = 0;
    Method *methods = class_copyMethodList([UIDevice class], &count);
    for (int i = 0; i < count; i++) {
        SEL sel = method_getName(methods[i]);
        NSString *selName = NSStringFromSelector(sel);
        NSLog(@"sel:%@",selName);
    }
    free(methods);
    
    UIDevice * device = [UIDevice currentDevice];
    SEL seletor = NSSelectorFromString(@"_deviceInfoForKey:");
    
    if ([device respondsToSelector:seletor]) {
        IMP imp = [device methodForSelector:seletor];
        NSString *(*func)(id,SEL,NSString *) = (void *)imp;
        NSString *deviceColor = func(device,seletor,@"DeviceColor");
        NSString *deviceEnclosureColor = func(device,seletor,@"DeviceEnclosureColor");
        NSLog(@"deviceColor:%@===deviceEnclosureColor:%@",deviceColor,deviceEnclosureColor);
    }
}

- (void)deviceIvar{
    unsigned int count = 0;
    // 属性名
    Ivar *ivars = class_copyIvarList([UIDevice class], &count);
    for (int i = 0; i < count; i++) {
        const char *name = ivar_getName(ivars[i]);
        NSString *strName = [NSString stringWithUTF8String:name];
        NSLog(@"name===%@",strName);
        
    }
    free(ivars);
    NSLog(@"==============");
    unsigned int count1 = 0;
    objc_property_t *propertys = class_copyPropertyList([UIDevice class], &count1);
    for (int i = 0; i < count1; i++) {
        const char *name = property_getName(propertys[i]);
        NSString *strName = [NSString stringWithUTF8String:name];
        
        const char *attr = property_getAttributes(propertys[i]);
        NSString *strAttr = [NSString stringWithUTF8String:attr];
        
        NSLog(@"name:%@===attr:%@",strName,strAttr);
        
    }
    free(propertys);
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    if ([keyPath isEqualToString:@"na"]) {
        NSLog(@"%@",change);
    }
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    UIViewController *vc = [NSClassFromString(@"AnimationViewController") new];
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

#pragma mark -- runtime
/*
 objc_msgSend:
 通过id和SEL确定唯一的方法实现
 */

/*
 Method:某种方法类型
 SEL方法名
 types:参数类型和返回值类型
 IMP：方法实现 是一个函数指针
 */

/*
 Ivar:实例变量类型
 class_copyIvarList：函数获取的不仅有实例变量，还有属性。但会在原本的属性名前加上一个下划线。
 */

/*
 objc_property_t:属性
 class_copyPropertyList protocol_copyPropertyList：方法来获取类和协议中的属性
 property_getName:属性名
 */


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
